package com.example.musicplayer.square;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.example.musicplayer.R;

public class Square_xq extends Activity {
    private SQLiteDatabase ds;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.square_xq);

        Refreshxq();
    }

    public void Refreshxq() {
        TextView name=(TextView)findViewById(R.id.te_name);
        TextView date=(TextView)findViewById(R.id.te_date);
        TextView comment1=(TextView)findViewById(R.id.te_1);
        TextView comment2=(TextView)findViewById(R.id.te_2);
        TextView comment3=(TextView)findViewById(R.id.te_3);
        TextView comment4=(TextView)findViewById(R.id.te_4);
        TextView comment5=(TextView)findViewById(R.id.te_5);
        TextView comment6=(TextView)findViewById(R.id.te_6);
        DBSquare Square = new DBSquare(this);
        ds = Square.getWritableDatabase();
        //获取输入的ID值
        Bundle bundle=this.getIntent().getExtras();
        String str1= bundle.getString("te1");
        //使用游标进行逐行查找
        Cursor cursor = ds.rawQuery("select * from Square where id = ?",new String[]{str1});
        while (cursor.moveToNext()) {
            int id = cursor.getInt(0);
            if (id == Integer.parseInt(str1)) {
                date.setText(cursor.getString(2));
                name.setText(cursor.getString(3));
                comment1.setText(cursor.getString(4));
                comment2.setText(cursor.getString(5));
                comment3.setText(cursor.getString(6));
                comment4.setText(cursor.getString(7));
                comment5.setText(cursor.getString(8));
                comment6.setText(cursor.getString(9));
            }
        }
    }
    public void btn_pinlun(View view){
        /**
         * ID更新
         */
        //连接数据库
        DBSquare Square = new DBSquare(this);
        ds = Square.getWritableDatabase();
        //获取插入的值
        EditText comm = (EditText)findViewById(R.id.et_sshuo);
        //获取输入的ID值
        Bundle bundle=this.getIntent().getExtras();
        String str1= bundle.getString("te1");
        String manname= bundle.getString("manname")+" : ";

        TextView comment1=(TextView)findViewById(R.id.te_1);
        TextView comment2=(TextView)findViewById(R.id.te_2);
        TextView comment3=(TextView)findViewById(R.id.te_3);
        TextView comment4=(TextView)findViewById(R.id.te_4);
        TextView comment5=(TextView)findViewById(R.id.te_5);
        TextView comment6=(TextView)findViewById(R.id.te_6);
        int q=0;
        ContentValues contentValues = new ContentValues();
        if (comment1.getText().toString()=="") {
            contentValues.put("comment1",manname+comm.getText().toString());}
        else{
            if (comment2.getText().toString()=="") {
                contentValues.put("comment2",manname+comm.getText().toString());}
            else{
                if (comment3.getText().toString()=="") {
                    contentValues.put("comment3",manname+comm.getText().toString());}
                else{
                    if (comment4.getText().toString()=="") {
                        contentValues.put("comment4",manname+comm.getText().toString());}
                    else{
                        if (comment5.getText().toString()=="") {
                            contentValues.put("comment5",manname+comm.getText().toString());}
                        else{
                            if (comment6.getText().toString()=="") {
                                contentValues.put("comment6",manname+comm.getText().toString());}
                            else{q=1;}
                        }
                    }
                }
            }
        }
        if(q==0){
            ds.update("Square",contentValues,"id=?",new String[]{str1});
            Refreshxq();}
    }






    public void btn_cancel(View view){
        this.finish();
//            Intent intent = new Intent(Square_man.this,Square_xq.class);    //收到消息后跳转
//            startActivity(intent);
    }
    public void btn_ok(View view){
        Intent intent = new Intent(Square_xq.this,Square.class);    //收到消息后跳转
        startActivity(intent);
    }
    public void btn_man(View view){
        Intent intent = new Intent(Square_xq.this,Square_man.class);    //收到消息后跳转
        DBSquare Square = new DBSquare(this);
        ds = Square.getWritableDatabase();
        //获取输入的ID值
        Bundle bundle=this.getIntent().getExtras();
        String str1= bundle.getString("te1");
        //使用游标进行逐行查找
        Cursor cursor = ds.rawQuery("select * from Square where id = ?",new String[]{str1});
        while (cursor.moveToNext()) {
            int id = cursor.getInt(0);
            if (id == Integer.parseInt(str1)) {
                Bundle bund=new Bundle();
                bund.putString("text", cursor.getString(1));
                intent.putExtras(bund);
                startActivity(intent);
            }
        }
    }

}
